package dao;

import pojo.User;
import utils.GetConnection;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class UserDao {
    public ArrayList findUserBySql(String sql) throws SQLException {
        ArrayList<User> userList=new ArrayList<User>();
        Connection conn= GetConnection.getConn();
        Statement stmt=conn.createStatement();
        System.out.println("数据库查询中....");
        System.out.println("sql语句:"+sql);
        ResultSet rs=stmt.executeQuery(sql);
        while(rs.next()) {
            User u=new User();
            u.setId(rs.getInt("id"));
            u.setUsername(rs.getString("username"));
            u.setPassword(rs.getString("password"));
            userList.add(u);
        }
        conn.close();
        stmt.close();
        return userList;
    }
}
